package com.jumi.microservice.controller.api;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jm.member.common.core.utils.ServletUtils;
import com.jm.member.common.core.web.page.TableDataInfo;
import com.jm.member.common.jwt.constant.JwtAdminInfo;
import com.jumi.microservice.common.base.dto.ResponseResult;
import com.jumi.microservice.domain.MessageTemplate;
import com.jumi.microservice.entity.JmFeedback;
import com.jumi.microservice.enums.FeedbackStatus;
import com.jumi.microservice.enums.Level;
import com.jumi.microservice.enums.MessageSendType;
import com.jumi.microservice.mq.SendMessageHandler;
import com.jumi.microservice.service.IJmFeedbackService;
import com.jumi.microservice.service.PageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;

@RestController
@RequestMapping("/api/feedback")
@Api(tags = "C-反馈接口")
public class FeedbackController {

    @Autowired
    IJmFeedbackService feedbackService;



    @PostMapping("/save")
    public ResponseResult saveFeedBack(@ApiParam(required = true,value = "反馈内容") @RequestParam String content){
        if(StrUtil.isEmpty(content)) return ResponseResult.error("反馈内容不能为空!");
        JmFeedback feedback=new JmFeedback();
        feedback.setContent(content);
        feedback.setCreateTime(LocalDateTime.now());
        feedback.setStatus(FeedbackStatus.待回复);
        feedback.setUid(ServletUtils.getIntHeader(JwtAdminInfo.apiUserId));
        feedbackService.save(feedback);
        return ResponseResult.success();
    }

    @GetMapping("/getMyFeedback")
    public TableDataInfo getMyFeedback(Integer size, Integer current){
        Integer uid = ServletUtils.getIntHeader(JwtAdminInfo.apiUserId);
        Page page=new Page(current,size);
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("uid",uid);
        wrapper.orderByDesc("id");
        page=feedbackService.getPage(page,wrapper);
        return PageService.getDataTableInfo(page);
    }
}
